package FCRendering;

import lombok.Getter;
import lombok.Setter;

import java.awt.Image;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.util.HashMap;
import java.util.Map;

/**
 * FCRMaster图片存放类
 * 
 * @author jungle
 *
 */
public class ImageUtil {

	public static ImageUtil imageUtil;

	public static Map<String, Image> images = new HashMap<>();


	@Getter
	private HashMap<String, TankImgWrap> tankImgWrapHashMap = new HashMap<>();
	public static ImageUtil getImageUtil(){
		return imageUtil;
	}

	static {
		imageUtil = new ImageUtil();
		// 主界面
		images.put("vword", Toolkit.getDefaultToolkit().getImage("./material/master/VWordGameStudio.png"));
		images.put("ZZJB", Toolkit.getDefaultToolkit().getImage("./material/master/ZhongZhuangJiBing.png"));
		images.put("mm", Toolkit.getDefaultToolkit().getImage("./material/master/MM.png"));
		images.put("de", Toolkit.getDefaultToolkit().getImage("./material/master/DATAEAST.png"));
		images.put("oneplayer2", Toolkit.getDefaultToolkit().getImage("./material/master/onePlayer2.png"));
		images.put("twoplayer2", Toolkit.getDefaultToolkit().getImage("./material/master/twoPlayer2.png"));
		images.put("oneplayer1", Toolkit.getDefaultToolkit().getImage("./material/master/onePlayer1.png"));
		images.put("twoplayer1", Toolkit.getDefaultToolkit().getImage("./material/master/twoPlayer1.png"));
		// info
		images.put("exitgame", Toolkit.getDefaultToolkit().getImage("./material/master/exit.png"));
		images.put("thankwin", Toolkit.getDefaultToolkit().getImage("./material/master/thanks.png"));
		images.put("returnmaster", Toolkit.getDefaultToolkit().getImage("./material/master/return.png"));
		// 创房与找房
		images.put("fond", Toolkit.getDefaultToolkit().getImage("./material/master/fond.png"));
		images.put("create", Toolkit.getDefaultToolkit().getImage("./material/master/create.png"));
		images.put("fondorcreate", Toolkit.getDefaultToolkit().getImage("./material/master/fondorcreate.png"));
		// 新建存档窗口
		images.put("getready", Toolkit.getDefaultToolkit().getImage("./material/getReady/getready.png"));
		images.put("newsave", Toolkit.getDefaultToolkit().getImage("./material/getReady/newsave.png"));
		// 房主窗口
		images.put("playerahouse", Toolkit.getDefaultToolkit().getImage("./material/getReady/playerahouse.png"));
		images.put("playerasetsave", Toolkit.getDefaultToolkit().getImage("./material/getReady/playerasetsave.png"));
		// 找房窗口
		images.put("playerbhouse", Toolkit.getDefaultToolkit().getImage("./material/getReady/playerbhouse.png"));
		images.put("playerbconnect", Toolkit.getDefaultToolkit().getImage("./material/getReady/playerbconnect.png"));
		// 加载资源界面
		images.put("loadingpng1", Toolkit.getDefaultToolkit().getImage("./material/master/loading1.png"));
		images.put("loadingpng2", Toolkit.getDefaultToolkit().getImage("./material/master/loading2.png"));
		// 游戏界面窗口资源
		images.put("gamemenuteamrequest", Toolkit.getDefaultToolkit().getImage("./material/game/game-team-request.png"));//
		images.put("gamemenu", Toolkit.getDefaultToolkit().getImage("./material/game/game-menu.png"));// 菜单底面
		images.put("gamemenucha", Toolkit.getDefaultToolkit().getImage("./material/game/game-menu-character.png"));// 菜单人物
		images.put("gamemenuchaarm",
				Toolkit.getDefaultToolkit().getImage("./material/game/game-menu-character-arm.png"));// 菜单人物
		images.put("gamemenutank", Toolkit.getDefaultToolkit().getImage("./material/game/game-menu-tanks.png"));// 菜单战车
		images.put("gamemenugarage", Toolkit.getDefaultToolkit().getImage("./material/game/game-menu-garage.png"));// 菜单车库
		images.put("gamemenusta", Toolkit.getDefaultToolkit().getImage("./material/game/game-menu-statistics.png"));// 菜单统计
		images.put("gamemenuset", Toolkit.getDefaultToolkit().getImage("./material/game/game-menu-setting.png"));// 菜单设置
		images.put("gametime", Toolkit.getDefaultToolkit().getImage("./material/game/game-time.png"));// 时间显示
		images.put("gameiteminfo", Toolkit.getDefaultToolkit().getImage("./material/game/game-iteminfo.png"));// 物品详情
		images.put("gameplayerinfo", Toolkit.getDefaultToolkit().getImage("./material/game/game-playerinfo.png"));// 玩家信息
		images.put("gametankinfo", Toolkit.getDefaultToolkit().getImage("./material/game/game-tanksinfo.png"));// 坦克信息
		images.put("gameplayerkna", Toolkit.getDefaultToolkit().getImage("./material/game/game-playerknapsack.png"));// 玩家背包
		images.put("gametankkna", Toolkit.getDefaultToolkit().getImage("./material/game/game-tanksknapsack.png"));// 坦克背包
		images.put("gamemenuopen", Toolkit.getDefaultToolkit().getImage("./material/game/game-menu-open.png"));// 菜单打开
		images.put("gamemenuclose", Toolkit.getDefaultToolkit().getImage("./material/game/game-menu-close.png"));// 菜单关闭
		images.put("gameitemshou", Toolkit.getDefaultToolkit().getImage("./material/game/game-item-shou.png"));// 手


		// 商店材质
		images.put("shopvendingmachine",
				Toolkit.getDefaultToolkit().getImage("./material/game/shop-vendingMachine.png"));// 自动售货机界面
		images.put("shoplampred", Toolkit.getDefaultToolkit().getImage("./material/game/shop-lamp-red.png"));// 自动售货机界面-红灯
		images.put("shoplampredbig", Toolkit.getDefaultToolkit().getImage("./material/game/shop-lamp-red-big.png"));// 自动售货机界面-皇冠
		// 战斗背景
		images.put("battleBG", Toolkit.getDefaultToolkit().getImage("./material/master/black.png"));// 战斗背景

		// 玩家人身战斗操作菜单
		images.put("battleplayermenu", Toolkit.getDefaultToolkit().getImage("./material/game/battle-player-menu.png"));// 玩家人身战斗操作菜单
		// 玩家坦克战斗操作菜单
		images.put("battletankmenu", Toolkit.getDefaultToolkit().getImage("./material/game/battle-tank-menu.png"));// 玩家坦克战斗操作菜单
		// 准心
		images.put("battlecrosshair", Toolkit.getDefaultToolkit().getImage("./material/game/battle-crosshair.png"));// 准心
		// 箱子窗口
		images.put("caseframe", Toolkit.getDefaultToolkit().getImage("./material/game/game-case.png"));
		// 聊天信息
		images.put("gamesayframe", Toolkit.getDefaultToolkit().getImage("./material/game/game-say-frame.png"));
		images.put("gamesayselectbutton",
				Toolkit.getDefaultToolkit().getImage("./material/game/game-say-select-button.png"));
		images.put("gamesayselectmenuhead",
				Toolkit.getDefaultToolkit().getImage("./material/game/game-say-select-menu-head.png"));
		images.put("gamesayselectmenubody",
				Toolkit.getDefaultToolkit().getImage("./material/game/game-say-select-menu-body.png"));
		images.put("gamesayselectmenufoot",
				Toolkit.getDefaultToolkit().getImage("./material/game/game-say-select-menu-foot.png"));
		images.put("gamesayshop", Toolkit.getDefaultToolkit().getImage("./material/game/game-say-shop.png"));
		// 复古留声机
		images.put("gamephonographframe",
				Toolkit.getDefaultToolkit().getImage("./material/game/game-phonograph-frame.png"));

		images.put("gamesayshopbuy",
				Toolkit.getDefaultToolkit().getImage("./material/game/game-say-shop-buy.png"));

		images.put("gamefightmenu",
				Toolkit.getDefaultToolkit().getImage("./material/game/game-fight-menu.png"));
		images.put("gamefightfengyin",
				Toolkit.getDefaultToolkit().getImage("./material/game/game-fight-fengyin.png"));
		images.put("ready",
				Toolkit.getDefaultToolkit().getImage("./material/png/character/ready.png"));
		images.put("mubei",
				Toolkit.getDefaultToolkit().getImage("./material/png/character/mubei.png"));
		images.put("menudead",
				Toolkit.getDefaultToolkit().getImage("./material/game/game-fight-menu-dead.png"));
		images.put("gamefightsayframe",
				Toolkit.getDefaultToolkit().getImage("./material/game/game-fightsay-frame.png"));
		images.put("disable",
				Toolkit.getDefaultToolkit().getImage("./material/game/disable.png"));
		images.put("gameshowplayerq",
				Toolkit.getDefaultToolkit().getImage("./material/game/game-show-player-q.png"));
		images.put("gamegun1bg",
				Toolkit.getDefaultToolkit().getImage("./material/game/game-gun1-bg.png"));
		images.put("playerlistbg1",
				Toolkit.getDefaultToolkit().getImage("./material/game/playerlistbg1.png"));
		images.put("playerlistbg2",
				Toolkit.getDefaultToolkit().getImage("./material/game/playerlistbg2.png"));
		images.put(FCRBattleOrderConstant.S_Acid,
				Toolkit.getDefaultToolkit().getImage("./material/png/state/stateSuan.png"));
		images.put(FCRBattleOrderConstant.S_Gas,
				Toolkit.getDefaultToolkit().getImage("./material/png/state/stateDu.png"));
		images.put(FCRBattleOrderConstant.S_Fire,
				Toolkit.getDefaultToolkit().getImage("./material/png/state/stateFire.png"));
		images.put(FCRBattleOrderConstant.S_Frozen,
				Toolkit.getDefaultToolkit().getImage("./material/png/state/stateFrozen.png"));
		images.put(FCRBattleOrderConstant.S_Paralysis,
				Toolkit.getDefaultToolkit().getImage("./material/png/state/stateMabi.png"));
		images.put(FCRBattleOrderConstant.S_Sleep,
				Toolkit.getDefaultToolkit().getImage("./material/png/state/stateSleep.png"));
		images.put(FCRBattleOrderConstant.S_Fog,
				Toolkit.getDefaultToolkit().getImage("./material/png/state/statefog.png"));
		images.put(FCRBattleOrderConstant.S_Confusion,
				Toolkit.getDefaultToolkit().getImage("./material/png/state/stateHunluan.png"));
		images.put("gamebattlelistfoot",
				Toolkit.getDefaultToolkit().getImage("./material/game/game-battle-list-foot.png"));
		images.put("gamebattlelisthead",
				Toolkit.getDefaultToolkit().getImage("./material/game/game-battle-list-head.png"));
		images.put("gamebattlelistbody",
				Toolkit.getDefaultToolkit().getImage("./material/game/game-battle-list-body.png"));
		images.put("gamehelp",
				Toolkit.getDefaultToolkit().getImage("./material/game/game-help.png"));
		images.put("gamehelp-I",
				Toolkit.getDefaultToolkit().getImage("./material/game/game-help-I.png"));
		images.put("world",
				Toolkit.getDefaultToolkit().getImage("./material/png/mapImg/world.png"));
		images.put("positionflag",
				Toolkit.getDefaultToolkit().getImage("./material/game/positionflag.png"));
		images.put("game_glove_bg",
				Toolkit.getDefaultToolkit().getImage("./material/game/game_glove_bg.png"));
		images.put("talkbg",
				Toolkit.getDefaultToolkit().getImage("./material/game/talkbg.png"));
	}

	/**
	 * 根据key获取图片
	 * 
	 * @param key
	 * @return
	 */
	public static Image getImage(String key) {
		return images.get(key);
	}

	public static Image getMapImage(String mapName){
		Image ret = getImage(mapName);
		if(ret != null){
			return ret;
		}
		ret = Toolkit.getDefaultToolkit().getImage("./material/png/mapImg/"+mapName+".png");
		images.put(mapName, ret);
		return ret;
	}

	public static boolean checkContainImage(String key) {
		return images.containsKey(key);
	}

	public static class TankImgWrap{

		public Image imageUp[] = new BufferedImage[4];
		// 坦克向下走素材

		public Image imageDown[] = new BufferedImage[4];
		// 坦克向左走素材

		public Image imageLeft[] = new BufferedImage[4];
		// 坦克向右走素材

		public Image imageRight[] = new BufferedImage[4];
	}

	public Image getTankMoveImg(String key, int dir, int num){
		TankImgWrap wrap = tankImgWrapHashMap.get(key);
		switch (dir) {
			case 3:// up
				return wrap.imageUp[num];
			case 0:// down
				return wrap.imageDown[num];
			case 1:// left
				return wrap.imageLeft[num];
			default:// right
				return wrap.imageRight[num];
		}
	}
}